<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/1.2.1/axios.js"></script>
</head>

<body>
    <div>http://api.zhibao.com:3000/students</div>
    <button>添加学员</button>
    <button>获取学员</button>
    <ul></ul>
    <div>https://v1.hitokoto.cn</div>
    <button>获取一言数据</button>
    <p></p>
    <script>
        // 获取ul和按钮
        let ul = document.querySelector('ul');
        let btns = document.querySelectorAll('button');
        let p = document.querySelector('p');

        // 1. 创建axios实例
        // console.log(axios.create({config}));
        let jsonAxios = axios.create({
            method:"get",
            baseURL:"http://api.zhibao.com:3000"
        })

        // console.log(jsonAxios); // 返回的函数 - 将代替axios本身！
        //添加学员
        btns[0].onclick =async function(){
           let res =await jsonAxios.post('/students',{
            name:"灰太狼",
            age:88,
            score:19
           });
           console.log(res);
        }

        //获取学员
        btns[1].onclick =async function(){
           let {data} = await jsonAxios("/students");
           console.log(data);
        }

        // 2. 创建 axios实例
        let yiyanAxios = axios.create({
            method:"get",
            baseURL:"https://v1.hitokoto.cn"
        });

        // 获取一言数据
        btns[2].onclick =async function(){
           let {data} = await yiyanAxios('/',{
               params:{
                   c:"c"
               }
           });

           console.log(data);
        }
        
    </script>
</body>

</html>